import request from '../../utils/request'
import Constants from '../../utils/Constants'

/**
 * 分页查询业务参数
 * @param sprCode
 * @param page
 * @returns {Promise.<Object>}
 */
export async function getBusinessParamsList({sprCode, page}) {
    return request(apiPath.basedata + "/api/businessParams", {
        method: 'get',
        data: { sprCode , page: page.page, size: page.size, appCode: Constants.APPCODE}
    });
}

/**
 * 业务参数详情
 * @param sprCode
 * @param sprName
 * @returns {Promise.<Object>}
 */
export async function getBusinessParamsById({sprCode, sprName}) {
    return request(apiPath.basedata + "/api/businessParams/" + sprCode +"/" + sprName, {
        method: 'get'
    });
}

/**
 * 创建业务参数
 * @param sprCode
 * @param sprName
 * @param sprValue
 * @param sprSortWeights
 * @param sprDesc
 * @param userId
 * @returns {Promise.<Object>}
 */
export async function addBusinessParams({sprCode, sprName, sprValue, sprSortWeights, sprDesc, isEnabled, userId}) {
    userId =1;
    let creator = userId;
    sprSortWeights = 1;
    return request(apiPath.basedata + "/api/businessParams", {
        method: 'post',
        data: { sprCode, sprName, sprValue, sprSortWeights, sprDesc, userId, isEnabled, creator}
    });
}

/**
 * 修改业务参数
 * @param sprCode
 * @param sprName
 * @param sprValue
 * @param sprSortWeights
 * @param sprDesc
 * @param userId
 * @returns {Promise.<Object>}
 */
export async function updateBusinessParams({sprCode, sprName, sprValue, sprSortWeights, sprDesc, isEnabled, userId}) {
    userId =1;
    let updater = userId;
    sprSortWeights = 1;
    return request(apiPath.basedata + "/api/businessParams", {
        method: 'put',
        data: { sprCode, sprName, sprValue, sprSortWeights, sprDesc, userId, isEnabled, updater}
    });
}


/**
 * 删除业务参数
 * @param sprCode
 * @param sprName
 * @returns {Promise.<Object>}
 */
export async function deleteBusinessParamsById({sprCode, sprName}) {
    return request(apiPath.basedata + "/api/businessParams/" + sprCode +"/" + sprName, {
        method: 'delete'
    });
}

/**
 * 根据sprCode获取参数集合
 *
 * @param sprCode
 * @returns {Promise.<void>}
 */
export async function getBusinessParamsByCode({sprCode}) {
    return request(apiPath.basedata + "/api/allBusinessParams", {
        method: 'get',
        data: {sprCode}
    });
}

/**
 * 根据sprCode列表
 */
export async function getAllBusinessParamCode() {
    return request(apiPath.basedata + "/api/businessParams/allCode", {
        method: 'get',
        data: {appCode: Constants.APPCODE}
    });
}
